from django.db import models

# Create your models here.

class Hardware(models.Model):
	'''服务器硬件基础类'''
	status_id = ((1,'Online'),(2,'Stop'),(3,'废弃'))
	id = models.AutoField(primary_key=True)
	minion_id = models.CharField(max_length=32,unique=True,verbose_name="主机名")      #客户端的minion 配置的id默认是主机名，直接拿id即可
	localhost = models.CharField(max_length=32,verbose_name="主机命名")
	manufacturer  = models.CharField(max_length=32,verbose_name="厂商")  #厂商
	cpu_model = models.CharField(max_length=32,verbose_name="CPU信息")      #Cpu信息
	cpuarch  = models.CharField(max_length=32,verbose_name="CPU架构")     #cpu架构
	kernel  = models.CharField(max_length=32,verbose_name="内核")      #内核
	kernelrelease  = models.CharField(max_length=32,verbose_name="内核版本")  #内核版本
	machine_id  = models.CharField(max_length=32,verbose_name="内核序列号")   #内核的唯一序列号
	mem_total  = models.CharField(max_length=32,verbose_name="内存总数")  #物理总内存
	num_cpus  = models.CharField(max_length=32,verbose_name="CPU个数")   #CPU个数
	osfullname   = models.CharField(max_length=32,verbose_name="系统名称") #系统全名
	productname  = models.CharField(max_length=32,verbose_name="硬件型号") #硬件型号
	serialnumber   = models.CharField(max_length=32,verbose_name="主机S/N码")    #主机唯一的s/n码,厂商提供
	status = models.IntegerField(choices=status_id,verbose_name="状态",default=1)
	engineroom_id = models.ForeignKey('EngineRoom',verbose_name="机房位置",null=True,default=None)  #外键关联的由脚本填入
	create_time = models.DateTimeField(verbose_name='收录时间',auto_now_add=True)
	end_time = models.DateTimeField(verbose_name='最后修改时间',auto_now=True)
	# networkinfo_id = models.ManyToManyField('NetworkInfo',verbose_name="IP地址",null=True)
	# diskuseinfo_id = models.ManyToManyField('DiskUseInfo',verbose_name="磁盘情况",null=True)

	def __str__(self):
		return self.minion_id
	class Meta:
		db_table = 'OPS_cmdb_hardware'
		verbose_name_plural = '资产信息'

class EngineRoom(models.Model):
	'''机房位置信息'''
	line_type = ((1,'电信'),(2,'联通'),(3,'移动'),(4,"双线"),(5,'其他'))
	id = models.AutoField(primary_key=True)
	room = models.CharField(max_length=16,verbose_name="机房")
	line = models.IntegerField(choices=line_type,verbose_name="线路",default=4)
	def __str__(self):
		return self.room
	class Meta:
		db_table = 'OPS_cmdb_engineroom'
		verbose_name_plural = '机房管理'


class NetworkInfo(models.Model):
	'''网卡信息'''
	id = models.AutoField(primary_key=True)
	ipaddress = models.GenericIPAddressField(unpack_ipv4=False,verbose_name='IP地址')
	server = models.ForeignKey('Hardware',verbose_name='所属主机')
	def __str__(self):
		return self.ipaddress
	class Meta:
		db_table = 'OPS_cmdb_networkinfo'
		verbose_name_plural = 'IP地址'


class DiskUseInfo(models.Model):
	id = models.AutoField(primary_key=True)
	mount = models.CharField(max_length=32,verbose_name="挂载名",default='None')
	blocks = models.CharField(max_length=32,verbose_name="磁盘大小",default='None')
	capacity = models.CharField(max_length=32,verbose_name="已使用比例",default='None')
	filesystem = models.CharField(max_length=32,verbose_name="磁盘分区",default='None')
	server = models.ForeignKey('Hardware', verbose_name='所属主机',default=1)
	def __str__(self):
		return self.mount
	class Meta:
		db_table = 'OPS_cmdb_diskuseinfo'
		verbose_name_plural = '磁盘管理'


